<template>
	<view :style="skin" class="content" id="startPage">
		<view class="startPage">
			<!-- <image src="https://cloudmate-1257437764.cos.ap-guangzhou.myqcloud.com/img/bg_img.png" mode=""></image> -->

			<view class="logo">
				<!-- 				<image mode="widthFix" :style="{ height: imgHeight + 'px' }" @load="onImgLoad"
					src="https://cloudmate-1257437764.cos.ap-guangzhou.myqcloud.com/img/wellgreen_logo.png"></image> -->

				<!-- <view class="tips">
						<text class="powered">Powered by </text> 腾讯连连
					</view> -->

			</view>


			<fui-safe-area background="var(--backSubject)"></fui-safe-area>
		</view>
	</view>
</template>

<script>
	import {
		mapState
	} from 'vuex'
	import {
		appKey,
		isDebug,
		versions
	} from '@/utils/requestURL.js'
	import {
		formatDateTime
	} from '@/utils/index.js'
	import {
		logout
	} from '@/api/login.js'
	export default {
		data() {
			return {
				timer: null,
				imgHeight: 0,
			}
		},
		onShow() {


			let overdueLogin = uni.getStorageSync('overdueLogin')
			if (overdueLogin) {
				uni.showToast({
					title: 'Login expired, please login again',
					duration: 2000,
					icon: 'none'
				})
			}
			let accessToken = uni.getStorageSync('accessToken')
			if (accessToken) {
				//偶现首页无家庭无设备，加个处理超过七天未使用，直接重新登录
				// let time = uni.getStorageSync('last_time')
				// let nowTime = new Date().getTime()
				// uni.setStorageSync('last_time',nowTime)
				// if(time&&nowTime-time>1000*60*60*24*7){
				// 	this.timer = setTimeout(() => {
				// 		uni.redirectTo({
				// 			url: '/pages/login/login'
				// 		})
				// 	}, 2000)
				// 	let StorageFamily = uni.getStorageSync('StorageFamily')
				// 	let AccountList = uni.getStorageSync('AccountList')
				// 	uni.clearStorageSync()
				// 	uni.setStorageSync('StorageFamily', StorageFamily)
				// 	uni.setStorageSync('AccountList', AccountList)
				// 	return
				// }
				this.timer = setTimeout(() => {
					let sync_flag = uni.getStorageSync('sync_flag');
					console.log(sync_flag);
					if (sync_flag == 9) {
						uni.switchTab({
							url: '/pages/home/home'
						})
					} else {
						uni.showLoading({
							title: 'Loading',
							mask: false
						});
						logout().then(res => {
							if (res.code == 0) {
								console.log(res);
								uni.showToast({
									title: 'Log out successfully',
									icon: 'none'
								});
								let lang = uni.getStorageSync('lang')
								uni.clearStorageSync();
								uni.setStorageSync('lang', lang);

								uni.redirectTo({
									url: '/pages/login/login'
								})
							}else{
								uni.showToast({
									title: res,
									icon: 'none'
								});
							}
						})

					}

					uni.setStorageSync('overdueLogin', false)
				}, 2000)
			} else {

				this.timer = setTimeout(() => {

					uni.redirectTo({
						url: '/pages/login/login'
					})
					uni.setStorageSync('overdueLogin', false)


				}, 2000)


			}
		},
		onHide() {
			this.timer && clearTimeout(this.timer)
		},
		methods: {
			onImgLoad(e) {

				const {
					width,
					height
				} = e.mp.detail;
				this.imgHeight = (height / width) * 100;
			},
		},
		computed: {
			...mapState({
				skin: state => state.theme.skin
			})

		},

	}
</script>

<style scoped lang="scss">
	.startPage {
		height: 100%;
		position: relative;

		image {
			width: 100%;
			height: 100%;
		}

		.logo {
			position: absolute;
			top: 50%;
			left: 50%;
			transform: translate(-50%, -50%);
			width: 360rpx;

			.tips {
				width: 100%;
				height: 54rpx;
				text-align: center;
				font-size: 36rpx;
				line-height: 54rpx;
				color: var(--subtopicTextColor);
				margin-top: 24rpx;
				font-weight: 600;

				.powered {
					font-size: 24rpx;
					line-height: 24rpx;
					margin-right: 8rpx;
				}
			}
		}



	}
</style>